<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Number</title>
    <script src="js/traceur.js"></script>
    <script src="js/bootstrap.js"></script>

    <script>
        var a = 017;
        var b = 15;

        console.log(a === b); //true
        console.log(a); //15
    </script>

    <script type="module">
        //二进制
        let a = 0b00001111;
        let b = 15;
        console.log(a === b ); //true
        console.log(a); //15

        //八进制
        let a1 = 0o17;
        let b1 = 15;
        console.log(a1 === b1); //true
        console.log(a1); //15

        //判断为整数
        let a2 = 17.0;
        let b2 = 1.2;
        console.log(Number.isInteger(a2)); //true
        console.log(Number.isInteger(b2)); //false

        //判断数字
        let a3 = "NaN";
        let b3 = NaN;
        let c3 = "hello";
        let d3 = 12;

        console.log(Number.isNaN(a3));//false
        console.log(Number.isNaN(b3));//true
        console.log(Number.isNaN(c3));//false
        console.log(Number.isNaN(d3));//false
        console.log(isNaN(a3)); //true
        console.log(isNaN(b3)); //true
        console.log(isNaN(c3)); //true
        console.log(isNaN(d3)); //false

        //判断数字的范围
        console.log("ES5: \n");
        console.log(isFinite(10)); //true
        console.log(isFinite(NaN)); //false
        console.log(isFinite(null)); //true
        console.log(isFinite([])); //true
        console.log("ES6:\n" + Number.isFinite(10)); //true
        console.log(Number.isFinite(NaN)); //false
        console.log(Number.isFinite(null)); //false
        console.log(Number.isFinite([])); //false

        //JavaScript中整数的最大
        console.log("数字范围判断：\n" + Number.isSafeInteger(156)); //true
        console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER)); //true
        console.log(Number.isSafeInteger(Number.MAX_SAFE_INTEGER + 1)); //false
        console.log(Number.isSafeInteger(Number.MIN_SAFE_INTEGER)); //true
        console.log(Number.isSafeInteger(Number.MIN_SAFE_INTEGER - 1)); //false


        //浮点数
        console.log("浮点数：\n"+ 0.1 + 0.2 == 0.3); //false
        console.log(0.9 - 0.8 == 0.1); //false
        console.log(0.1 + 0.2); //0.30000000000000004
        console.log(0.9 - 0.8); //0.09999999999999998


        console.log("利用误差来进行判断：\n");
        function epsilonEqual(a, b) {
            return Math.abs(a-b) < Number.EPSILON;
        }
        console.log(epsilonEqual(0.1+0.2, 0.3)); //true
        console.log(epsilonEqual(0.9-0.8, 0.1)); //true

    </script>
</head>
<body>

</body>
</html>